package com.able.concurrency.t5;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * @author abel.he
 * @data 2018/10/29 13:22
 * @describe
 * 无容量限制线程池。最大容量为Integer.MAX_VALUE
 * 默认线程空闲 60 秒，自动销毁
 */
public class Test4_CachedThreadPoll {

    public static void main(String[] args) throws InterruptedException {
        ExecutorService service = Executors.newCachedThreadPool();

        for (int i = 0; i < 5; i++) {
            service.submit(new Runnable() {
                @Override
                public void run() {
                    try {
                        TimeUnit.MILLISECONDS.sleep(500);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + " - test execute");
                }
            });
        }

        System.out.println(service);
        TimeUnit.SECONDS.sleep(65);
        System.out.println(service);

    }

}
